package com.shudes.eval;

import java.util.*;

import com.shudes.game.*;

public class MonteCarloEnumerator {

	protected Set<Board> boards;
	
	protected CardCollection board;
	protected CardCollection knownCards;
	protected int sampleSize;
	protected int cardsPerSet;
			
	public MonteCarloEnumerator(CardCollection board, CardCollection knownCards, int sampleSize) {
		this.sampleSize=sampleSize;
		this.board=board;
		this.knownCards=knownCards;
		
		if(this.board==null) {
			this.board = new CardCollection(0);
		}
		
		if(this.knownCards==null) { 
			this.knownCards = new CardCollection(0);
		}
			
		this.cardsPerSet = 5-this.board.size();
		
		buildBoards();
	}
	
	public Set<Board> getBoards() { 
		return this.boards; 
	}
	
	protected void buildBoards() {
		Deck deck;
		Set<Card> cards;
		
		boards=new HashSet<Board>();		
		for(int count=0; count<sampleSize;count++) {
			cards = new HashSet<Card>();
			deck = newDeck();
			cards.addAll(board.getCards()); 
			cards.addAll(deck.deal(this.cardsPerSet).getCards()); 
			boards.add(new Board(cards)); 
		}
	}
	
	protected Deck newDeck() {
		Deck deck = new Deck();
		
		for(Iterator<Card> it=board.iterator(); it.hasNext();) { 
			deck.remove(it.next()); 						
		}
		
		for(Iterator<Card> i=knownCards.iterator(); i.hasNext();) { 
			deck.remove(i.next()); 
		}		
		
		deck.shuffle();
		return deck;		
	}

}
